define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;


    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>确定是否提交？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });



    var _vm = Init.initVue({
        data : {
            id : null,
            tip : null,
            rtip : null,
            check : {},
            res : {
                team_sn : "",
                type : "",
                r_benefit : "",
                leader : "",
                leader_name : "",
                income_acct : "",
                income_acct_name : "",
                company : ""
            }
        },
        methods: {
            submit : function() {
                var url, flag, s, r;

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) { return; }

                s = new String(_vm.res.team_sn);
                r = +[_vm.res.r_benefit];

                if (s.length < 3) {
                    _vm.tip = "团队号为3位纯数字";
                    return;
                } else if (s.charAt(s.length - 1) == 0) {
                    _vm.tip = "团队号末尾不能为0";
                    return;
                } else if (r < 0 || r > 100) {
                    _vm.tip = null;
                    _vm.rtip = "请输入0～100的整数";
                    return;
                } else {
                    _vm.tip = null;
                    _vm.rtip = null;
                }

                if (_vm.id) {
                    url = "team/sn/modify";
                    _vm.res.team_id = _vm.id
                } else {
                    url = "team/sn/create";
                }

                _Dialog.showUI(function(i) {
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax(url,{ data: JSON.stringify(_vm.res)},{type : 'post'}).done(function(){
                            METHOD.loading.hide();
                            METHOD.alert("操作成功").done(function(){
                                window.location.href = "../team/no.html";
                            });
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }
                    this.hideUI();
                });
            },
            getInfoCallback1 : function(obj) {
                if (obj) {
                    this.res.leader_name = obj.name;
                    if (!this.res.income_acct) {
                        this.res.income_acct = this.res.leader;
                        this.getInfoCallback2(obj);
                    }
                } else {
                    this.res.leader_name = "";
                }
            },
            getInfoCallback2 : function(obj) {
                if (obj) {
                    this.res.income_acct_name = obj.name;
                } else {
                    this.res.income_acct_name = "";
                }
            }
        }
    });

    _vm.id = METHOD.getQueryParms("id") || null;

    if (_vm.id) {
        METHOD.loading.show();
        METHOD.ajax("team/sn/detail",{team_id:_vm.id}).done(function(json){
            METHOD.loading.hide();
            _vm.res = json.data;
        }).fail(function(){
            METHOD.loading.hide();
        })
    }

});

